﻿using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

public class ShowSkins : EditorWindow
{

    int index = 0;

    [MenuItem("Tools/检查皮肤")]
    static void CheckSkins()
    {
        ShowSkins window = (ShowSkins)GetWindow(typeof(ShowSkins), true, "检查皮肤", true);
        window.Show();

    }

    private void OnEnable()
    {
        GameObject selectionObj = Selection.activeGameObject;

        for (int i = 1; i < selectionObj.transform.childCount; i++)
        {
            selectionObj.transform.GetChild(i).gameObject.SetActive(false);
        }
    }
    private void OnDisable()
    {
        ShowOrHide(true);
    }


    private void OnGUI()
    {
        GUILayout.BeginHorizontal();
        GUILayout.Label("检查皮肤", EditorStyles.boldLabel);
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        if (GUILayout.Button("上一个皮肤", GUILayout.Height(150), GUILayout.Width(150)))
        {
            LastSkin();
        }
        if (GUILayout.Button("下一个皮肤", GUILayout.Height(150), GUILayout.Width(150)))
        {
            NextSkin();
        }
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        if (GUILayout.Button("显示所有皮肤"))
        {
            ShowOrHide(true);
        }
        if (GUILayout.Button("隐藏所有皮肤"))
        {
            ShowOrHide(false);
        }
        GUILayout.EndHorizontal();
    }

    private void ShowOrHide(bool isShow)
    {
        GameObject selectionObj = Selection.activeGameObject;

        for (int i = 0; i < selectionObj.transform.childCount; i++)
        {
            selectionObj.transform.GetChild(i).gameObject.SetActive(isShow);
        }
    }


    private void LastSkin()
    {
        GameObject selectionObj = Selection.activeGameObject;
        if (selectionObj.name == "Skins")
        {
            selectionObj.transform.GetChild(index).gameObject.SetActive(false);

            if (--index < 0)
                index = selectionObj.transform.childCount - 1;

            selectionObj.transform.GetChild(index).gameObject.SetActive(true);
        }
        else
        {
            EditorUtility.DisplayDialog("提示", "请选择Skins", "OK");
        }
    }
    private void NextSkin()
    {
        GameObject selectionObj = Selection.activeGameObject;
        if (selectionObj.name == "Skins")
        {
            selectionObj.transform.GetChild(index).gameObject.SetActive(false);

            if (++index >= selectionObj.transform.childCount)
                index = 0;

            selectionObj.transform.GetChild(index).gameObject.SetActive(true);
        }
        else
        {
            EditorUtility.DisplayDialog("提示", "请选择Skins", "OK");
        }
    }


}
